<?php defined('SYSPATH') or die('No direct script access.');
   
class Controller_Admin extends Controller_Admin_Common
{
    public function close()
    {
        if(isset($_POST['exit']))
                {
                    Cookie::delete('login');
                    Cookie::delete('pas');
                    Cookie::delete('id');
                    $this->redirect('entry/login');
                }
    } 
    public function entry()
    {
        $users = ORM::factory('user')
            ->where( 'login', '=', Cookie::get('login', 'no user'))
            ->find();
        if($users->loaded())
        {
            if($users->accesses==1)
            {
              $this->close();  
            }
            else
            {
                $this->redirect('entry/login');
            }
        }
        else
        {
             $this->redirect('entry/login');
        }
    }
    public function action_adm()
    {
        $this->entry();
        $sidebar = View::factory('admin/adm');
        $this->template->sidebar = $sidebar;
        $content = View::factory('admin/hello');
        $this->template->content = $content;
    }
    public function action_search()
    {
      //  $this->entry();
      //  $sidebar = View::factory('admin/adm');
      //  $this->template->sidebar = $sidebar;
       // $content = View::factory('admin/search');
      //  $this->template->content = $content; 
        $this->redirect('home/index');
    }
     
    public function action_users()
    {
        $this->entry();
        $sidebar = View::factory('admin/adm');
        $this->template->sidebar = $sidebar;
        $content = View::factory('admin/users');
        $this->template->content = $content;
    }
    public function action_realtor()
    {
        $this->entry();
        $sidebar = View::factory('admin/adm');
        $this->template->sidebar = $sidebar;
        $content = View::factory('admin/realtor');
        $this->template->content = $content;
    }
    public function action_company()
    {
        $this->entry();
        $sidebar = View::factory('admin/adm');
        $this->template->sidebar = $sidebar;
        $content = View::factory('admin/company');
        $this->template->content = $content;
    }
    public function action_statistic()
    {
        $this->entry();
        $sidebar = View::factory('admin/adm');
        $this->template->sidebar = $sidebar;
        $content = View::factory('admin/statistic');
        $this->template->content = $content;
    }
    public function action_bid()
    {
        $this->entry();
        if(isset($_POST["det"]))
        {
            $a=$_POST["idus"];
            Cookie::set('temp', $a);       
            $this->redirect('admin/details');
        }
        $content = View::factory('admin/bid');
        $this->template->content = $content;
        $sidebar = View::factory('admin/adm');
        $this->template->sidebar = $sidebar;         
    }  
    public function action_details()
    {
        $this->entry();
        $users = ORM::factory('user')
                ->where( 'id', '=', Cookie::get('temp','no user'))
                ->find();
            if($users->loaded())
            {
                $data = array(
                    'id' => $users->id,
                    'name' => $users->initials,
                    'login' => $users->login,
                    'email' => $users->email,
                    'phone' => $users->phone,
                    'document' => $users->document->document1
                );          
            }
        
        if(isset($_POST["delete"]))
        {
            ORM::factory('user', $users->id)
                ->delete();
             $this->redirect('admin/bid');
            
        }
        if(isset($_POST["confirm"]))
        {
            $data2 = array('confirm' => 1);
            ORM::factory('user', $users->id)
                ->values($data2)->save();
             $this->redirect('admin/bid');
        }
        
        $content = View::factory('admin/details', $data);
        $this->template->content = $content;
        $sidebar = View::factory('admin/adm');
        $this->template->sidebar = $sidebar;
    
    }
  
 } //end Controller_Admin  
 
 
 
 